#pragma once 
#include <iostream>
#include <string>
#include <cstdio>
#include <functional>

class Task
{
public:
    using fun_t = std::function<int(int,int,char)>;
    typedef std::function<int(int,int)> func_t;
public:
    Task()
    {}
    Task(const int x,const int y,char op,fun_t func)
        :_x(x),_y(y),_op(op),_callback(func)
    {}
    std::string operator()()
    {
        int result = _callback(_x,_y,_op);
        char buffer[128];
        snprintf(buffer,sizeof buffer," %d %c %d = %d ",_x,_op,_y,result);
        return buffer;
    }
    std::string to_Task_string()
    {
        char buffer[128];
        snprintf(buffer,sizeof buffer," %d %c %d = ? ",_x,_op,_y);
        return buffer;
    }
    ~Task()
    {}
private:
    int _x;
    int _y;
    char _op;
    fun_t _callback;
};
const string oper = "+-*/%";    //运算符号
int mymath(int x,int y,char op)
{
    int result = 0;
    switch(op)
    {
        case '+':
            result = x + y;
            break;
        case '-':
            result = x - y;
            break;
        case '*':
            result = x * y;
            break;
        case '/':
        {
            if(y == 0)
            {
                cerr<<"div zero err" << endl;
                result = -1;
            }
            else 
                result = x / y;
            break;
        }
        case '%':
        {
            if(y == 0)
            {
                cerr<<"mod zero err" << endl;
                result = -1;
            }
            else 
                result = x % y;
            break;
        }
    }
    return result;
}
